﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Role : MonoBehaviour {
    [HideInInspector]
    public int cur_side;    // 0左，1右，-1在水中央
    [HideInInspector]
    public int cur_pos;
    public int type;

    static Vector3 g = new Vector3(0.0f, -9.8f, 0.0f);
    static float jump_t = 0.5f;
    float acc_t;
    bool jumping;
    Vector3 jump_v0, jump_des;
    
    public void Init() {
        cur_side = 1;
        jumping = false;
    }
    void Start() {
        
    }
    void Update() {
        if (!jumping) {
            return;
        }
        transform.position += Time.deltaTime * jump_v0;
        transform.position += g * acc_t * Time.deltaTime + 0.5f * g * Time.deltaTime * Time.deltaTime;
        acc_t += Time.deltaTime;
        if (acc_t >= jump_t) {
            acc_t = 0;
            jumping = false;
            transform.position = jump_des;
        }
    }
    
    public bool IsJumping() {
        return jumping;
    }
    public bool StartJumping(Vector3 des) {
        if (jumping) {
            return false;
        }
        jumping = true;
        acc_t = 0;
        jump_des = des;
        jump_v0.x = (des.x - transform.position.x) / jump_t;
        jump_v0.y = (des.y - transform.position.y) / jump_t - 0.5f * g.y * jump_t;
        jump_v0.z = 0;
        return true;
    }
}
